package com.sky.mapper;


import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    List<Category> selectCategoryByName(String name, Integer type);

    @AutoFill(OperationType.INSERT)
    void insertCategory(Category category);

    @Delete("delete from category where id = #{id}")
    void deleteCategoryById(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateCategory(Category category);

    Category selectCategoryById(Long id);

    @Select("select id, type, name, sort, status, create_time, update_time, create_user, update_user" +
            " from category where type = #{type}")
    List<Category> selectCategoryByType(Integer type);

    @Select("select count(*) from category where name = #{name}")
    Integer selectCountNameById(String name);

    @Select("select count(*) from category where sort = #{sort}")
    Integer selectCountSortById(Integer type);

    @Select("select count(*) from category where sort = #{sort} and id != #{id}")
    Integer selectCountSortByIdNotSelf(Long id,Integer sort);

    @Select("select count(*) from category where name = #{name} and id != #{id}")
    Integer selectCountNameByIdNotSelf(Long id,String name);

    @Select("select id, type, name, sort, status, create_time, update_time, create_user, update_user" +
            " from category")
    List<Category> selectCategory();
}
